package ${package}.action;

/**
 * ${description}
 *
 * @author ${author}
 * @version ${createDate}
 */
@SuppressWarnings("unchecked")
public class ${beanName}Action extends BaseAction {

	/**
	 * 列表.
	 * 
	 * @param context
	 * @return ${jspPath}/${uncapitalizeBeanName}List.jsp
	 * @throws Exception
	 */
	@Override
	public ActionForward doDefault(BActionContext context) throws Exception {
		
		${beanName}Service ${uncapitalizeBeanName}Service = (${beanName}Service) context.findService("${uncapitalizeBeanName}Service", ${beanName}Service.class);
		${beanName}Form ${uncapitalizeBeanName}Form = (${beanName}Form) context.getForm();
		
		BaseResultModel baseResultModel = new BaseResultModel();
		baseResultModel.setResults(${uncapitalizeBeanName}Service.get${beanName}(${uncapitalizeBeanName}Form));
		context.setBean("result", baseResultModel, BActionContext.SCOPE_REQUEST);
		${uncapitalizeBeanName}Form.getSearchModel().getPage().fillPageWithParameter(context.getRequest());
		baseResultModel.setPage(${uncapitalizeBeanName}Form.getSearchModel().getPage());
		
		IOperationLog logservice = (IOperationLog) context.findService("operationLog", IOperationLog.class);
		LogInfo loginfo = new LogInfo(RequestUtil.getUserBasic(context).getMc(), Module.AUTHORITY.AUTHORITYASSIGN, "", RequestUtil.getUserBasic(context).getIp());
		logservice.operateHtLog(loginfo, "查看 [${description}列表] 成功", "1");
		return context.findForward("list");
	}

	/**
	 * 新增.
	 * 
	 * @param context
	 * @return ${jspPath}/${uncapitalizeBeanName}Save.jsp
	 * @throws Exception
	 */
	public ActionForward save(BActionContext context) throws Exception {
		
		${beanName}Service ${uncapitalizeBeanName}Service = (${beanName}Service) context.findService("${uncapitalizeBeanName}Service", ${beanName}Service.class);
		${beanName}Form ${uncapitalizeBeanName}Form = (${beanName}Form) context.getForm();
		
		IOperationLog logservice = (IOperationLog) context.findService("operationLog", IOperationLog.class);
		LogInfo loginfo = new LogInfo(RequestUtil.getUserBasic(context).getMc(), Module.AUTHORITY.AUTHORITYASSIGN, "", RequestUtil.getUserBasic(context).getIp());
		if (${uncapitalizeBeanName}Service.save(${uncapitalizeBeanName}Form)) {
			logservice.operateHtLog(loginfo, "新增 [${description}] 成功", "1");
			context.setBean("cb", "yes", BActionContext.SCOPE_REQUEST);
		} else {
			StringBuffer message = new StringBuffer("新增 [${description}] 失败 :");
			Map<String, Class> mapProp = ReflectionUtil.getAllProperties(${uncapitalizeBeanName}Form.getClass());
			message.append("param : [");
			for (String key : mapProp.keySet()) {
				message.append(key).append(" : ").append(MyBeanUtils.invokeReadMethod(key, ${uncapitalizeBeanName}Form)).append(", ");
			}
			message.append("]");
			logservice.operateHtLog(loginfo, message.toString(), "0");
			this.saveDirectlyMessage(context.getRequest(), "操作失败");
		}
		this.saveDirectlyMessage(context.getRequest(), "操作成功");
		return context.findForward("save");
	}
	
	/**
	 * 修改.
	 * 
	 * @param context
	 * @return ${jspPath}/${uncapitalizeBeanName}Edit.jsp
	 * @throws Exception
	 */
	public ActionForward update(BActionContext context) throws Exception {
		
		${beanName}Service ${uncapitalizeBeanName}Service = (${beanName}Service) context.findService("${uncapitalizeBeanName}Service", ${beanName}Service.class);
		${beanName}Form ${uncapitalizeBeanName}Form = (${beanName}Form) context.getForm();
		
		IOperationLog logservice = (IOperationLog) context.findService("operationLog", IOperationLog.class);
		LogInfo loginfo = new LogInfo(RequestUtil.getUserBasic(context).getMc(), Module.AUTHORITY.AUTHORITYASSIGN, "", RequestUtil.getUserBasic(context).getIp());
		if (${uncapitalizeBeanName}Service.update(${uncapitalizeBeanName}Form)) {
			logservice.operateHtLog(loginfo, "修改 [${description}] 成功", "1");
			context.setBean("cb", "yes", BActionContext.SCOPE_REQUEST);
		} else {
			StringBuffer message = new StringBuffer("修改 [${description}] 失败 :");
			Map<String, Class> mapProp = ReflectionUtil.getAllProperties(${uncapitalizeBeanName}Form.getClass());
			message.append("param : [");
			for (String key : mapProp.keySet()) {
				message.append(key).append(" : ").append(MyBeanUtils.invokeReadMethod(key, ${uncapitalizeBeanName}Form)).append(", ");
			}
			message.append("]");
			logservice.operateHtLog(loginfo, message.toString(), "0");
			this.saveDirectlyMessage(context.getRequest(), "操作失败");
		}
		this.saveDirectlyMessage(context.getRequest(), "操作成功");
		return context.findForward("edit");
	}
	
	/**
	 * 删除.
	 * 
	 * @param context
	 * @return @return ${jspPath}/${uncapitalizeBeanName}List.jsp
	 * @throws Exception
	 */
	public ActionForward delete(BActionContext context) throws Exception {
		
		${beanName}Service ${uncapitalizeBeanName}Service = (${beanName}Service) context.findService("${uncapitalizeBeanName}Service", ${beanName}Service.class);
		${beanName}Form ${uncapitalizeBeanName}Form = (${beanName}Form) context.getForm();
		
		IOperationLog logservice = (IOperationLog) context.findService("operationLog", IOperationLog.class);
		LogInfo loginfo = new LogInfo(RequestUtil.getUserBasic(context).getMc(), Module.AUTHORITY.AUTHORITYASSIGN, "", RequestUtil.getUserBasic(context).getIp());
		if (${uncapitalizeBeanName}Service.delete(${uncapitalizeBeanName}Form.getId())) {
			logservice.operateHtLog(loginfo, "删除 [${description}] 成功", "1");
		} else {
			logservice.operateHtLog(loginfo, "删除 [${description}] 失败 : param [id :" + ${uncapitalizeBeanName}Form.getId() + " ]", "0");
			this.saveDirectlyMessage(context.getRequest(), "操作失败");
		}
		this.saveDirectlyMessage(context.getRequest(), "操作成功");
		return doDefault(context);
	}
	
	/**
	 * 打开修改页面.
	 * 
	 * @param context
	 * @return ${jspPath}/${uncapitalizeBeanName}Edit.jsp
	 * @throws Exception
	 */
	public ActionForward goEdit(BActionContext context) throws Exception {

		${beanName}Service ${uncapitalizeBeanName}Service = (${beanName}Service) context.findService("${uncapitalizeBeanName}Service", ${beanName}Service.class);
		${beanName}Form ${uncapitalizeBeanName}Form = (${beanName}Form) context.getForm();
		
		${beanName} model = ${uncapitalizeBeanName}Service.get(${uncapitalizeBeanName}Form.getKeyValue());
		context.setBean("model", model, BActionContext.SCOPE_REQUEST);
		return context.findForward("edit");
	}
	
	/**
	 * 打开新增页面.
	 * 
	 * @param context
	 * @return ${jspPath}/${uncapitalizeBeanName}Save.jsp
	 * @throws Exception
	 */
	public ActionForward goSave(BActionContext context) throws Exception {

		return context.findForward("save");
	}
	
}
